﻿
CREATE TABLE [DBMMCatalogs](
	[CatalogID] [int] NOT NULL,
	[ConnectionID] [int] NOT NULL,
	[Name] [varchar](50) NOT NULL,
PRIMARY KEY
(
	[CatalogID] ASC
)
)

;


CREATE TABLE [DBMMConnections](
	[ConnectionID] [int] NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Type] [smallint] NOT NULL,
	[IsSource] [char](1) NOT NULL,
	[ConnectParams] [text] NOT NULL,
	[ConnectString] [text] NOT NULL,
	[Properties] [varchar](2000) NULL,
PRIMARY KEY
(
	[ConnectionID] ASC
)
)

;


CREATE TABLE [DBMMFieldMappings](
	[FieldMappingID] [int] NOT NULL,
	[ReplicationID] [int] NOT NULL,
	[IsForth] [char](1) NOT NULL,
	[TrgFieldID] [int] NOT NULL,
	[SrcFieldID] [int] NULL,
	[SrcExpression] [text] NULL,
PRIMARY KEY
(
	[FieldMappingID] ASC
)
)

;


CREATE TABLE [DBMMFields](
	[FieldID] [int] NOT NULL,
	[TableID] [int] NOT NULL,
	[Name] [varchar](100) NOT NULL,
	[Ordinal] [int] NOT NULL,
	[Type] [varchar](50) NOT NULL,
	[InternalType] [int] NOT NULL,
	[Size] [int] NOT NULL,
	[Precision] [smallint] NOT NULL,
	[Scale] [smallint] NOT NULL,
	[Ccsid] [int] NULL,
	[AllowNull] [char](1) NOT NULL,
	[DateFormat] [varchar](10) NULL,
	[Description] [varchar](1000) NULL,
	[PrimaryKeyPos] [int] NOT NULL,
	[IsAutoIncrement] [char](1) NOT NULL,
	[Default] [varchar](50) NULL,
PRIMARY KEY
(
	[FieldID] ASC
)
)

;


CREATE TABLE [DBMMForeignKeys](
	[ForeignKeyID] [int] NOT NULL,
	[TableID] [int] NOT NULL,
	[FieldID] [int] NOT NULL,
	[Name] [varchar](100) NULL,
	[ForeignKeyPos] [int] NOT NULL,
	[RefCatalogName] [varchar](100) NULL,
	[RefSchemaName] [varchar](100) NULL,
	[RefTableName] [varchar](100) NULL,
	[RefFieldName] [varchar](100) NULL,
PRIMARY KEY
(
	[ForeignKeyID] ASC
)
)

;


CREATE TABLE [DBMMGroups](
	[GroupID] [int] NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Type] [smallint] NOT NULL,
	[Description] [varchar](150) NULL,
	[Properties] [varchar](2000) NULL,
PRIMARY KEY
(
	[GroupID] ASC
)
)

;


CREATE TABLE [DBMMReplications](
	[ReplicationID] [int] NOT NULL,
	[SrcTableID] [int] NOT NULL,
	[TrgTableID] [int] NOT NULL,
	[GroupID] [int] NULL,
	[Name] [varchar](50) NOT NULL,
	[Description] [varchar](150) NULL,
	[ReplMode] [int] NOT NULL,
	[AutomaticFieldsMapping] [char](1) NOT NULL,
	[UseScript] [char](1) NOT NULL,
	[ScriptModule] [text] NULL,
	[Properties] [varchar](2000) NULL,
	[ReplStatus] [int] NULL,
	[ReplLastExit] [int] NULL,
	[StartTime] [bigint] NULL,
	[RefreshLastDate] [bigint] NULL,
	[MirroringLastDate] [bigint] NULL,
	[UseRefreshSchedule] [char](1) NOT NULL,
	[UseMirroringSchedule] [char](1) NOT NULL,
	[ReplHistoryExit] [int] NULL,
PRIMARY KEY
(
	[ReplicationID] ASC
)
)

;


CREATE TABLE [DBMMReplStatuses](
	[ReplicationID] [int] NOT NULL,
	[IsForth] [char](1) NOT NULL,
	[TransactionID] [varchar](100) NULL,
	[TransactionTS] [bigint] NULL,
	[Properties] [varchar](2000) NULL,
	[TotalRecords] [bigint] NULL,
	[ProcessedRecords] [bigint] NULL,
	[FailedRecords] [bigint] NULL,
	[CommitTID] [varchar](100) NULL,
PRIMARY KEY
(
	[ReplicationID] ASC,
	[IsForth] ASC
)
)

;


CREATE TABLE [DBMMSchedules](
	[ScheduleID] [int] NOT NULL,
	[ReplicationID] [int] NOT NULL,
	[IsRefresh] [char](1) NOT NULL,
	[Recurrence] [smallint] NOT NULL,
	[Every] [int] NULL,
	[Month] [int] NULL,
	[Day] [int] NULL,
	[Time1] [int] NULL,
	[Len1] [int] NULL,
	[Time2] [int] NULL,
	[Len2] [int] NULL,
	[Time3] [int] NULL,
	[Len3] [int] NULL,
	[Time4] [int] NULL,
	[Len4] [int] NULL,
	[Time5] [int] NULL,
	[Len5] [int] NULL,
PRIMARY KEY
(
	[ScheduleID] ASC
)
)

;


CREATE TABLE [DBMMSchemas](
	[SchemaID] [int] NOT NULL,
	[ConnectionID] [int] NOT NULL,
	[CatalogID] [int] NULL,
	[Name] [varchar](50) NOT NULL,
PRIMARY KEY
(
	[SchemaID] ASC
)
)

;


CREATE TABLE [DBMMSysValues](
	[SysValueID] [int] NOT NULL,
	[ID] [varchar](50) NOT NULL,
	[Value] [varchar](50) NULL,
	[ValueLong] [text] NULL,
PRIMARY KEY
(
	[SysValueID] ASC
)
)

;


CREATE TABLE [DBMMTables](
	[TableID] [int] NOT NULL,
	[ConnectionID] [int] NOT NULL,
	[CatalogID] [int] NULL,
	[SchemaID] [int] NULL,
	[Name] [varchar](100) NOT NULL,
	[Type] [varchar](20) NOT NULL,
	[SysName] [varchar](100) NULL,
	[Version] [varchar](20) NULL,
	[Description] [varchar](1000) NULL,
	[Properties] [varchar](2000) NULL,
PRIMARY KEY
(
	[TableID] ASC
)
)

;